home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Inne / Gry / Carnage_Contest / scripts / CC Original / weapons / Minigun.lua < prev    next >
Text File  |  2010-09-27  |  6KB  |  171 lines

  1. --------------------------------------------------------------------------------
  2. -- Weapon Minigun + Projectile Bullet
  3. -- Original Carnage Contest Weapon
  4. -- Script by DC, August 2009, www.UnrealSoftware.de
  5. --------------------------------------------------------------------------------
  6.  
  7. -- Setup Tables
  8. if cc==nil then cc={} end
  9. cc.minig={}
  10. cc.minig.bullet={}
  11.  
  12. -- Load & Prepare Ressources
  13. cc.minig.gfx_wpn=loadgfx("weapons/minigun.bmp")                    -- Weapon Image
  14. setmidhandle(cc.minig.gfx_wpn)
  15. cc.minig.gfx_pro=loadgfx("weapons/shot.bmp")                    -- Projectile Image
  16. setmidhandle(cc.minig.gfx_pro)
  17. cc.minig.sfx_attack=loadsfx("mg.wav")                            -- Attack Sound
  18.  
  19. --------------------------------------------------------------------------------
  20. -- Weapon: Minigun
  21. --------------------------------------------------------------------------------
  22.  
  23. cc.minig.id=addweapon("cc.minig","Minigun",cc.minig.gfx_wpn,1)    -- Add Weapon (1 use)
  24. cc.minig.ammo=50                                                -- 50 Bullets
  25.  
  26. function cc.minig.draw()                                        -- Draw
  27.     setblend(blend_alpha)
  28.     setalpha(1)
  29.     setcolor(255,255,255)
  30.     drawinhand(cc.minig.gfx_wpn,6,0)
  31.     -- HUD ammobar
  32.     if cc.minig.ammo-weapon_shots>0 then
  33.         hudammobar(cc.minig.ammo-weapon_shots,cc.minig.ammo)
  34.     end
  35.     -- HUD Crosshair
  36.     if cc.minig.ammo-weapon_shots>0 then
  37.         hudcrosshair(7,3)
  38.     end
  39. end
  40.  
  41. function cc.minig.attack(attack)                                -- Attack
  42.     -- Decrement timer
  43.     if weapon_timer>0 then
  44.         weapon_timer=weapon_timer-1
  45.     end
  46.     -- Start burst
  47.     if attack==1 then
  48.         -- No more weapon switching!
  49.         useweapon(0)
  50.         weapon_mode=1
  51.     end
  52.     -- Attack
  53.     if weapon_shots<cc.minig.ammo and weapon_timer<=0 and weapon_mode==1 then
  54.         -- Reset Timer
  55.         weapon_timer=4
  56.         -- Attack
  57.         playsound(cc.minig.sfx_attack)
  58.         weapon_shots=weapon_shots+1
  59.         id=createprojectile(cc.minig.bullet.id)
  60.         projectiles[id]={}
  61.         -- Ignore collision with current player at beginning
  62.         projectiles[id].ignore=playercurrent()
  63.         -- Set initial position of projectile
  64.         projectiles[id].x=getplayerx(0)+(7*getplayerdirection(0))-math.sin(math.rad(getplayerrotation(0)))*5.0
  65.         projectiles[id].y=getplayery(0)+3+math.cos(math.rad(getplayerrotation(0)))*5.0
  66.         -- Set speed of projectile
  67.         randomseed(weapon_shots*12345)
  68.         offset=-4.0+random()*8.0
  69.         projectiles[id].sx=math.sin(math.rad(getplayerrotation(0)+offset))*15.0
  70.         projectiles[id].sy=-math.cos(math.rad(getplayerrotation(0)+offset))*15.0
  71.         -- Initial movement
  72.         projectiles[id].x=projectiles[id].x-projectiles[id].sx*1.5
  73.         projectiles[id].y=projectiles[id].y-projectiles[id].sy*1.5
  74.         for i=1,3,1 do
  75.             if cc.minig.bullet.move(id)==1 then
  76.                 break
  77.             end
  78.         end
  79.         -- Effects
  80.         recoil(3)
  81.         particle(p_muzzle,getplayerx(0)+(getplayerdirection(0)*7)+math.sin(math.rad(getplayerrotation(0)))*16,getplayery(0)+3-math.cos(math.rad(getplayerrotation(0)))*16)
  82.         particle(p_smoke,getplayerx(0)+(getplayerdirection(0)*7)+math.sin(math.rad(getplayerrotation(0)))*16,getplayery(0)+3-math.cos(math.rad(getplayerrotation(0)))*16)
  83.         particlespeed(-0.2+math.random()*0.4+getwind()*10.0,-1.0+math.random()*0.6)
  84.         particlefadealpha(0.005)
  85.         particle(p_bullet,getplayerx(0)+(getplayerdirection(0)*5),getplayery(0)+3)
  86.         -- End Turn
  87.         if (weapon_shots>=cc.minig.ammo) then
  88.             endturn()
  89.         end
  90.     end
  91. end
  92.  
  93. --------------------------------------------------------------------------------
  94. -- Projectile: Bullet
  95. --------------------------------------------------------------------------------
  96.  
  97. cc.minig.bullet.id=addprojectile("cc.minig.bullet")            -- Add Projectile
  98.  
  99. function cc.minig.bullet.draw(id)                            -- Draw
  100.     -- Setup draw mode
  101.     setblend(blend_light)
  102.     setalpha(1)
  103.     setcolor(255,255,0)
  104.     setscale(1,1)
  105.     -- Calculate projectile rotation
  106.     setrotation(math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy)))
  107.     -- Draw projectile
  108.     drawimage(cc.minig.gfx_pro,projectiles[id].x,projectiles[id].y)
  109.     -- Draw Arrow if out of Screen
  110.     outofscreenarrow(projectiles[id].x,projectiles[id].y)
  111. end
  112.  
  113. function cc.minig.bullet.update(id)                            -- Update
  114.     -- Wind + Gravity influence on speed
  115.     projectiles[id].sx=projectiles[id].sx+getwind()*0.02
  116.     projectiles[id].sy=projectiles[id].sy+getgravity()*0.75
  117.     -- Move
  118.     cc.minig.bullet.move(id)
  119. end
  120.  
  121. function cc.minig.bullet.move(id)
  122.     rot=math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy))
  123.     -- Move (in substep loop for optimal collision precision)
  124.     msubt=math.ceil(math.max(math.abs(projectiles[id].sx),math.abs(projectiles[id].sy))/3)
  125.     msubx=projectiles[id].sx/msubt
  126.     msuby=projectiles[id].sy/msubt
  127.     for i=1,msubt,1 do
  128.         projectiles[id].x=projectiles[id].x+msubx
  129.         projectiles[id].y=projectiles[id].y+msuby        
  130.         -- Collision
  131.         if collision(col3x3,projectiles[id].x+math.sin(math.rad(rot))*20,projectiles[id].y-math.cos(math.rad(rot))*20)==1 then
  132.             if terraincollision()==1 or objectcollision()>0 or playercollision()~=projectiles[id].ignore then
  133.                 -- Cause damage
  134.                 if playercollision()~=0 and playercollision()~=projectiles[id].ignore then
  135.                     playerpush(playercollision(),projectiles[id].sx/10.0,projectiles[id].sy/10.0)
  136.                     playerdamage(playercollision(),1)
  137.                     blood(projectiles[id].x+math.sin(math.rad(rot))*20,projectiles[id].y-math.cos(math.rad(rot))*20)
  138.                 elseif objectcollision()>0 then
  139.                     objectdamage(objectcollision(),1)
  140.                 end
  141.                 -- Destroy terrain
  142.                 for j=20,22,1 do
  143.                     terraincircle(projectiles[id].x+math.sin(math.rad(rot))*j,projectiles[id].y-math.cos(math.rad(rot))*j,3,0x00000000)
  144.                 end
  145.                 -- Effects
  146.                 playsound(sfx_ricochet1)
  147.                 particle(p_smoke,projectiles[id].x+math.sin(math.rad(rot))*21,projectiles[id].y-math.cos(math.rad(rot))*21)
  148.                 particlefadealpha(0.006)
  149.                 particle(p_muzzle,projectiles[id].x+math.sin(math.rad(rot))*21,projectiles[id].y-math.cos(math.rad(rot))*21)
  150.                 -- Free projectile
  151.                 freeprojectile(id)
  152.                 return 1
  153.             end
  154.         else
  155.             projectiles[id].ignore=0
  156.         end
  157.         -- Water
  158.         if (projectiles[id].y)>getwatery()+5 then
  159.             -- Effects
  160.             particle(p_waterhit,projectiles[id].x,projectiles[id].y)
  161.             if math.random(1,2)==1 then
  162.                 playsound(sfx_hitwater2)
  163.             else
  164.                 playsound(sfx_hitwater3)
  165.             end
  166.             -- Free projectile
  167.             freeprojectile(id)
  168.             return 1
  169.         end
  170.     end
  171. end